package com.iot.service.mqtt.bridge;

import com.iot.service.mqtt.model.request.TlMqttPublishReq;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: hszhou
 * @Date: 2025/5/12 14:39
 * @Description: 必须描述类做什么事情, 实现什么功能
 */

public class TlSubject {

    /**
     * 添加观察者
     */
    private final List<AbstractBridgeObserver> observers = new ArrayList<>();

    public void notifyAllObservers(String clientId, int qos, TlMqttPublishReq message){
        for (AbstractBridgeObserver observer : observers) {
            observer.forward(clientId,qos,message);
        }
    }

    public void attach(AbstractBridgeObserver observer) {
        observers.add(observer);
    }

    public void detach(AbstractBridgeObserver observer) {
        observers.remove(observer);
    }
}
